﻿using System;
namespace DoFactory.GangOfFour.Abstract.Structural
{
    /// <summary>
    /// The 'Client' class. Interaction environment for the products.
    /// </summary>
    class Client
    {
        private string nume;
        private int varsta;
        private ObjectPoolMasini lista_masini;


        public void set_varsta(int n) { varsta = n; }
        public int get_varsta() { return varsta; }

        public void set_nume(string n) { nume = n; }
        public string get_nume() { return nume; }

      
        public void afisare()
        {
            Console.WriteLine("Clientul {0} cu varsta {1} are masinile:", nume, varsta);
            foreach (AbstractMasina m in lista_masini._masini)
            {
                m.afisare();
            }
        }

        public void sterge(string nume)
        {
            int x = 0;
            foreach (AbstractMasina m in lista_masini._masini)
                if (m.get_nume() == nume)
                {
                    lista_masini._masini.Remove(m);
                    Console.WriteLine("S-a sters masina cu numele {0}", nume);
                    x = 1;
                    break;
                }
            if(x==0)
                Console.WriteLine("Nu exista masina cu numele {0}", nume);
        }

        // Constructor
        public Client(AbstractFactory factory1,AbstractFactory factory2,AbstractFactory factory3)
        {
            Console.WriteLine("Nume:");
            set_nume(Console.ReadLine());
            Console.WriteLine("Varsta:");
            set_varsta(Int32.Parse(Console.ReadLine()));

            lista_masini = ObjectPoolMasini.getInstance(factory1,factory2,factory3);
        }
}
}
